package com.douxg.fastCoding.db.clickhouse;

import com.douxg.fastCoding.db.DbDataType;
import com.douxg.fastCoding.db.JavaDbDataType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.ibatis.type.JdbcType;

/**
 * @Description
 * @Auther douxg
 * @Date 2020/11/12 11:42
 */
@Getter
@AllArgsConstructor
public enum CkDbDataType implements DbDataType {
    String(JdbcType.LONGNVARCHAR, JavaDbDataType.STRING),
    DateTime(JdbcType.TIMESTAMP, JavaDbDataType.DATE),
    Date(JdbcType.DATE, JavaDbDataType.LOCAL_DATE),
    UInt8(JdbcType.TINYINT, JavaDbDataType.INTEGER),
    UInt16(JdbcType.TINYINT, JavaDbDataType.INTEGER),
    UInt32(JdbcType.TINYINT, JavaDbDataType.LONG),
    UInt64(JdbcType.TINYINT, JavaDbDataType.BIG_INTEGER),
    Int8(JdbcType.TINYINT, JavaDbDataType.BYTE),
    Int16(JdbcType.SMALLINT, JavaDbDataType.SHORT),
    Int32(JdbcType.INTEGER, JavaDbDataType.INTEGER),
    Int64(JdbcType.BIGINT, JavaDbDataType.LONG);

    private JdbcType mybatisJdbcType;
    private JavaDbDataType javaDbDataType;

    public static CkDbDataType getByName(String name) {
        if (name != null) {
            for (CkDbDataType value : values()) {
                if (value.name().toLowerCase().equals(name) || value.name().equals(name)) {
                    return value;
                }
            }
        }
        return null;
    }

    @Override
    public boolean isDateTime() {
        if (this == DateTime || this == Date) {
            return true;
        }
        return false;
    }
}
